<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../../../static/css/public.css" media="all" />
</head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox" has-permission="00450005">
			<div class="layui-inline">
				<label class="layui-form-label">时间</label>
				<div class="layui-inline">
					<input type="text" class="layui-input searchVal" id="date" name="dateStr">
				</div>
			</div>
			<div class="layui-inline">
				<a class="layui-btn search-btn" data-type="reload">搜索</a>
			</div>
		</blockquote>
		<table id="list" lay-filter="list"></table>
	</form>
	<script type="text/javascript" src="../../../static/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../../static/layui/layui.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/common.js"></script>
	<script type="text/javascript">
		layui.use([ 'form', 'layer', 'table', 'laytpl', 'laydate' ], function() {
			var listApi = '../../../paid/paid/listSelf';
			var pram = merger(constant.page.toUri(), getsearchVal());
			var form = layui.form, layer = parent.layer === undefined ? layui.layer : top.layer;
			var $ = layui.jquery;
			var laytpl = layui.laytpl;
			var table = layui.table;
			var laydate = layui.laydate;

			//获取上一个月
			function getBeforeMonth() {
				var d = new Date();
				var currentYear = new Date().getFullYear();
				var currentMonth = new Date().getMonth() + 1;
				var beforeMonth = currentMonth - 1;
				if (beforeMonth == 0) {
					currentYear -= 1;
					beforeMonth = 12;
				}
				if (beforeMonth < 10) {
					beforeMonth = "0" + beforeMonth;
				}
				return currentYear + "-" + beforeMonth;
			}
			//执行一个laydate实例
			laydate.render({
				elem : '#date',
				type : 'month',
				value : getBeforeMonth()
			});
			//用户列表
			//listLoad(getsearchVal());
			function listLoad(data) {
				loadAjax(listApi, "get", data, function(response) {
					baseCallBack(response, function(response) {
						var data = response.data;
						var eData = [];
						var paid = data.paid;
						var post = data.post;
						var employee = data.employee;
						//如果有薪酬，显示薪酬
						if (paid) {
							var cols = [ {
								field : 'ername',
								title : '姓名',
								align : "center"
							} ];
							var expression = paid.expression;
							var expressionArray = JSON.parse(expression);
							for (var j = 0; j < expressionArray.length; j++) {
								var obj = {
									field : expressionArray[j].key,
									title : expressionArray[j].name,
									align : "center",
									templet : function(d) {
										var str = "";
										str += '<div>' + d[this.field] + '</div>';
										return str;
									}
								}
								cols.push(obj);

							}
							cols.push({
								field : 'formula',
								title : '薪酬表达式',
								align : 'center',
								width : "10%"
							}, {
								field : "salary",
								title : "薪酬总额",
								align : "center",
								templet : function(d) {
									var str = "";
									str += '<div style="font-weight:bold;font-size:20px">' + (d.salary ? d.salary : "") + '</div>';
									return str;
								}
							});
							for (var j = 0; j < expressionArray.length; j++) {
								paid[expressionArray[j].key] = expressionArray[j].value;
							}
							eData.push(paid);
							tableIns = table.render({
								elem : '#list',
								cellMinWidth : constant.table.cellMinWidth,
								page : false,
								height : constant.table.height,
								cols : [ cols ],
								data : eData
							});
							//没有薪酬，显示岗位的薪酬构成
						} else if (post) {
							var cols = [ {
								field : 'rname',
								title : '姓名',
								align : "center"
							} ];
							eData.push(employee);
							var expression = post.expression;
							var expressionArray = JSON.parse(expression);
							for (var j = 0; j < expressionArray.length; j++) {
								var obj = {
									field : expressionArray[j].key,
									title : expressionArray[j].name,
								}
								cols.push(obj);

							}
							cols.push({
								field : 'formula',
								title : '薪酬表达式',
								align : 'center',
								width : "10%"
							}, {
								field : "salary",
								title : "薪酬总额",
								align : "center"
							});
							tableIns = table.render({
								elem : '#list',
								cellMinWidth : constant.table.cellMinWidth,
								page : false,
								height : constant.table.height,
								cols : [ cols ],
								data : eData
							});
						}

					});
				});
			}
			//搜索
			$(".search-btn").on("click", function() {
				if ($("#date").val() == "") {
					layer.msg('请选择日期', {
						icon : 5
					});
					return;
				}
				pram = merger(pram, getsearchVal());
				listLoad(pram);
			});

		})
	</script>
</body>
</html>